package com.ljkj.cordial.chat.presenter.response;

import android.app.Activity;

import com.lanjiu.pro.business.BusinessProtocolEntities;
import com.lanjiu.pro.business.BusinessProtocolMessages;
import com.ljkj.cordial.chat.dao.notify.GroupMemberTable;

public class GroupMemberDeleteProtocolResponse extends AResponseBusinessPresenter {
    @Override
    public void onResponse(Activity activity, boolean isOnScreen, String msgType, Object msg) {
        BusinessProtocolMessages.GroupMemberDeleteProtocol response = (BusinessProtocolMessages.GroupMemberDeleteProtocol) msg;
        if (response.hasRegisteredGroupMember()) {
            BusinessProtocolEntities.RegisteredGroupMember member = response.getRegisteredGroupMember();
            if (member.hasGroup()) {
                BusinessProtocolEntities.RegisteredGroup group = member.getGroup();
                delete(group.getGroupId(), member.getGroupMemberUserId());
            }
        } else if (response.hasTouristsGroupMember()) {
            BusinessProtocolEntities.TouristsGroupMember member = response.getTouristsGroupMember();
            if (member.hasGroup()) {
                BusinessProtocolEntities.TouristsGroup group = member.getGroup();
                delete(group.getGroupId(), member.getGroupMemberUserId());
            }
        }
    }

    @Override
    public void delete(String... id) {
        super.delete(id);
        GroupMemberTable.deleteByUserId(id[0], id[1]);
    }
}
